package com.intellagric.controller.facility;

import com.intellagric.common.bean.LayuiDataGridResult;
import com.intellagric.common.bean.ResponseMessage;
import com.intellagric.common.utils.UUIDUtils;
import com.intellagric.interfaces.facility.FacilityCategoryService;
import com.intellagric.pojo.FacilityCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class FacilityCategoryController {

    @Autowired
    private FacilityCategoryService facilityCategoryService;

    @RequestMapping("/facilityCategory/add")
    @ResponseBody
    public ResponseMessage addFacilityCategory(FacilityCategory FacilityCategory){
        FacilityCategory.setId(UUIDUtils.getID());
        FacilityCategory.setCreateDate(new Date(System.currentTimeMillis()));
        return facilityCategoryService.insertFacilityCategory(FacilityCategory);
    }

    @RequestMapping("/facilityCategory/edit")
    @ResponseBody
    public ResponseMessage editFacilityCategory(FacilityCategory FacilityCategory){
        return facilityCategoryService.editFacilityCategory(FacilityCategory);
    }

    @RequestMapping("/facilityCategory/delete")
    @ResponseBody
    public ResponseMessage deleteFacilityCategory(String id){
        return facilityCategoryService.deleteFacilityCategory(id);
    }

    @RequestMapping("/facilityCategory/batchdelete")
    @ResponseBody
    public LayuiDataGridResult batchDelete(@RequestParam("ids[]") String[] ids){
        return facilityCategoryService.batchDeleteFacilityCategory(ids);
    }

    @RequestMapping("/facilityCategory/getFacilityCategory")
    @ResponseBody
    public FacilityCategory getFacilityCategory(String facilityCategoryId){
        return (FacilityCategory) facilityCategoryService.selectFacilityCategoryById(facilityCategoryId).getData().get("categoryBean");
    }



    @RequestMapping("/facilityCategory/menu")
    @ResponseBody
    public LayuiDataGridResult getMenu(){
        return facilityCategoryService.getMenu();
    }

    @RequestMapping("/facilityCategory/search")
    @ResponseBody
    public LayuiDataGridResult search(int page, int limit, String keyword){
        return facilityCategoryService.getFacilityCategoryByKeyword(page,limit,keyword);
    }
    /**
     * 查询菜单树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/facilityCategory/treelist")
    @ResponseBody
    public List<FacilityCategory> getTreeList() {
        LayuiDataGridResult category=facilityCategoryService.getMenu();
        return category.getData();
    }

}
